#pragma once

#include "../LibBuildNG/Task.hpp"
#include "../Shared/Exception.hpp"

namespace BuildNG
{
  class PerlTask : public Task
  {
  public:
    static void                   init();
    static void                   shutdown();

    virtual void                  load_from_xml(const Xml::Element &xml);

    virtual void                  run(BuildContext &context) const;

    void                          set_args_from_string(const Glib::ustring &str);

  private:
    Glib::ustring                 script_file_name;
    std::vector<Glib::ustring>    args;

    Glib::ustring                 std_in_file_name;
    Glib::ustring                 std_out_file_name;
  };

  class PerlTaskException : public Exception
  {
  public:
    PerlTaskException(const Glib::ustring &msg)
      : Exception(msg)
    {
    }
    
    ~PerlTaskException() throw() { }
  };

  class PerlScriptException : public PerlTaskException
  {
  public:
    PerlScriptException(const Glib::ustring &script_name,const std::string &error_msg);
    ~PerlScriptException() throw() { }

    virtual Glib::ustring get_message() const;

  private:
    Glib::ustring script_name;
    std::vector<Glib::ustring> error_lines;
  };
}

